package com.ruoyi.web.controller.storeEmployeeCommission;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProductPackageItem;
import com.ruoyi.system.service.IProductPackageItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐商品（存储基础商品信息）Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="套餐商品")
@RestController
@RequestMapping("/system/productPackageItem")
public class ProductPackageItemController extends BaseController
{
    @Autowired
    private IProductPackageItemService productPackageItemService;

    /**
     * 查询套餐商品（存储基础商品信息）列表
     */
    @ApiOperation("查询套餐商品列表")
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<ProductPackageItem> list = productPackageItemService.selectProductPackageItemListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出套餐商品（存储基础商品信息）列表
     */
    @ApiOperation("导出套餐商品列表")
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "套餐商品（存储基础商品信息）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<ProductPackageItem> list = productPackageItemService.selectProductPackageItemListByName(storeName);
        ExcelUtil<ProductPackageItem> util = new ExcelUtil<ProductPackageItem>(ProductPackageItem.class);
        util.exportExcel(response, list, "套餐商品（存储基础商品信息）数据");
    }

    /**
     * 获取套餐商品（存储基础商品信息）详细信息
     */
    @ApiOperation("获取套餐商品详细信息")
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productPackageItemService.selectProductPackageItemById(id));
    }

    /**
     * 新增套餐商品（存储基础商品信息）列表
     */
    @ApiOperation("新增套餐商品列表")
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "套餐商品（存储基础商品信息）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPackageItem productPackageItem)
    {
        return toAjax(productPackageItemService.insertProductPackageItem(productPackageItem));
    }

    /**
     * 修改套餐商品（存储基础商品信息）列表
     */
    @ApiOperation("修改套餐商品列表")
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "套餐商品（存储基础商品信息）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPackageItem productPackageItem)
    {
        return toAjax(productPackageItemService.updateProductPackageItem(productPackageItem));
    }

    /**
     * 删除套餐商品（存储基础商品信息）列表
     */
    @ApiOperation("删除套餐商品列表")
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "套餐商品（存储基础商品信息）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productPackageItemService.deleteProductPackageItemByIds(ids));
    }
}
